package com.example.nyf.mapper.provider;

import com.example.nyf.entity.SysMenu;

import java.util.Map;

public class SysMenuProvider {

    public String listSysMenu(Map<String, Object> mp) {
        StringBuffer sb = new StringBuffer("select a.* from sys_menu a " +
                "left join sys_role_menu b on a.id = b.menu_id " +
                "left join sys_user_role c on b.role_id = c.role_id " +
                "left join sys_role d on c.role_id = d.id where 1=1 and menu_type!=2" );
        if(mp.get("user_id") != null && !mp.get("user_id").equals("") && !mp.get("user_id").equals(0)) {
            sb.append(" and c.user_id = "+mp.get("user_id")+" ");
        }
        if(mp.get("parent_id") != null && !"".equals(mp.get("parent_id"))) {
            sb.append(" and a.parent_id = "+mp.get("parent_id")+" ");
        }
        if(mp.get("id") != null && !"".equals(mp.get("id"))) {
            sb.append(" and a.id = "+mp.get("id")+" ");
        }
        sb.append(" order by order_num asc ");
        return sb.toString();
    }

    public String insertSysMenu(SysMenu sysMenu) {
        StringBuffer sb = new StringBuffer("insert into sys_menu(menu_name, parent_id, order_num, url, menu_type, " +
                " perms, icon, remark, add_user_id, add_user_name, add_time) values('"+sysMenu.getMenu_name()+"', "+sysMenu.getParent_id()+"" +
                " , "+sysMenu.getOrder_num()+", '"+sysMenu.getUrl()+"', "+sysMenu.getMenu_type()+" " +
                ", '"+sysMenu.getPerms()+"', '"+sysMenu.getIcon()+"', '"+sysMenu.getRemark()+"', "+sysMenu.getAdd_user_id()+" " +
                " , '"+sysMenu.getAdd_user_name()+"', "+sysMenu.getAdd_time()+")");
        return sb.toString();
    }

}
